package com.qzsoft.zhjd.common.excel.style;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;

import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams;
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;

/**
 * @ClassName ZhjdExcelExportStyler
 * @Description excel导出样式
 * @author linhuawei
 * @since 2022-04-02
 */
public class ZhjdExcelExportStyler implements IExcelExportStyler {

    /**
     * 大标题样式
     */
    private CellStyle headerStyle;

    /**
     * 每列标题样式
     */
    private CellStyle titleStyle;

    /**
     * 数据行样式
     */
    private CellStyle styles;

    public ZhjdExcelExportStyler(Workbook workbook) {
        headerStyle = workbook.createCellStyle();

        Font titleFont = workbook.createFont();
        titleFont.setBold(true);
        titleFont.setFontHeightInPoints((short) 12);
        titleStyle = workbook.createCellStyle();
        titleStyle.setBorderTop(BorderStyle.THIN);
        titleStyle.setBorderLeft(BorderStyle.THIN);
        titleStyle.setBorderBottom(BorderStyle.THIN);
        titleStyle.setBorderRight(BorderStyle.THIN);
        titleStyle.setAlignment(HorizontalAlignment.CENTER);
        titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        titleStyle.setFont(titleFont);

        Font font = workbook.createFont();
        font.setFontHeightInPoints((short) 12);
        styles = workbook.createCellStyle();
        styles.setBorderTop(BorderStyle.THIN);
        styles.setBorderLeft(BorderStyle.THIN);
        styles.setBorderBottom(BorderStyle.THIN);
        styles.setBorderRight(BorderStyle.THIN);
        styles.setVerticalAlignment(VerticalAlignment.CENTER);
        styles.setFont(font);
        styles.setWrapText(true);
    }

    @Override
    public CellStyle getHeaderStyle(short headerColor) {
        return headerStyle;
    }

    @Override
    public CellStyle getTitleStyle(short color) {
        return titleStyle;
    }

    @Override
    public CellStyle getStyles(boolean parity, ExcelExportEntity entity) {
        return styles;
    }

    @Override
    public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data) {
        return styles;
    }

    @Override
    public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams) {
        return styles;
    }

}
